//
//  default_Cell.m
//  pmmSS
//
//  Created by Mac book on 2017/9/26.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "default_Cell.h"


@implementation default_Cell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
    }
    return self;
}

-(void)initSubViews{


    WeakSelf(weakSelf);

    _icon_btn = [HMButton createButtonWithTitle:nil andTitleColor:nil andBgColor:[UIColor whiteColor] andImage:[UIImage imageNamed:@"shop_normal"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:101];



    _icon_btn.clipsToBounds = YES;
    
    _icon_btn.layer.cornerRadius = autoScaleH(10);

    [_icon_btn setImage:[UIImage imageNamed:@"order_selected"] forState:UIControlStateSelected];

    [self.contentView addSubview:_icon_btn];

    _icon_imageView  = [[UIImageView alloc]init];
    _icon_imageView.backgroundColor = [UIColor yellowColor];
//    [_icon_imageView setImage:[UIImage imageNamed:@"list_icon_shop"]];
    [_icon_imageView sd_setImageWithURL:[NSURL URLWithString:@"http://7xq2wz.com1.z0.glb.clouddn.com/ff2a50cdacc8952ad8ccfcbb3ccae3f1.jpg"]];
    [self.contentView addSubview:_icon_imageView];

    _title_label = [ HMLabel createLabelWithText:@"特价处理/批发 工型钢(H型钢) 特价处理/批发 工型钢(H型钢)" andTextColor:[UIColor blackColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(14)] andTextAlignment:NSTextAlignmentLeft];

    _title_label.numberOfLines = 2 ;

    [self.contentView addSubview:_title_label];

    _icon_price_label  = [ HMLabel createLabelWithText:@"￥" andTextColor:RGBA(252,74,0,1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(12)] andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_icon_price_label];

    _price_label  = [ HMLabel createLabelWithText:@"6688" andTextColor:RGBA(252,74,0,1) andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(18)] andTextAlignment:NSTextAlignmentLeft];

    [self.contentView addSubview:_price_label];


    _add_btn = [HMButton createButtonWithTitle:nil andTitleColor:nil andBgColor:[UIColor whiteColor] andImage:[UIImage imageNamed:@"count_max"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:102];

    _add_btn.clipsToBounds = YES;
    _add_btn.layer.cornerRadius = autoScaleH(10);

    [self.contentView addSubview:_add_btn];

    _number_textfield = [HMTextField createTextFieldWithText:nil andpLlaceholder:nil andTextColor:[UIColor lightGrayColor] andBgColor:nil andFont:nil andTextAlignment:NSTextAlignmentCenter andTextFieldViewMode:UITextFieldViewModeNever];

    [self.contentView addSubview:_number_textfield];

    _subtract_btn = [HMButton createButtonWithTitle:nil andTitleColor:nil andBgColor:[UIColor whiteColor] andImage:[UIImage imageNamed:@"count_min"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:103];

    _subtract_btn.clipsToBounds = YES;
    _subtract_btn.layer.cornerRadius = autoScaleH(10);

    [self.contentView addSubview:_subtract_btn];

        [_icon_btn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(weakSelf.contentView);
            make.left.mas_equalTo(autoScaleW(10));
            make.width.mas_equalTo(autoScaleW(20));
            make.height.mas_equalTo(autoScaleH(20));

        }];
        [_icon_imageView mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(weakSelf.contentView);
            make.left.mas_equalTo(autoScaleW(52));
            make.width.mas_equalTo(autoScaleW(68));
            make.height.mas_equalTo(autoScaleH(68));
        }];

        [_title_label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(_icon_imageView.mas_top).offset(autoScaleH(0));
             make.left.mas_equalTo(autoScaleW(141));
            make.width.mas_equalTo(autoScaleW(220));
            make.height.mas_equalTo(autoScaleH(40));

        }];

        [_icon_price_label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(autoScaleW(141));
            make.bottom.mas_equalTo(weakSelf.icon_imageView).offset(autoScaleH(-3));
            make.width.mas_equalTo(autoScaleW(10));
            make.height.mas_equalTo(autoScaleH(17));

        }];

        [_price_label mas_makeConstraints:^(MASConstraintMaker *make) {

             make.left.mas_equalTo(autoScaleW(156));
            make.bottom.mas_equalTo(weakSelf.icon_imageView).offset(autoScaleH(0));
            make.width.mas_equalTo(autoScaleW(70));
            make.height.mas_equalTo(autoScaleH(25));

        }];

        [_add_btn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(_price_label);
            make.right.mas_equalTo(autoScaleW(-10));
            make.width.mas_equalTo(autoScaleW(20));
            make.height.mas_equalTo(autoScaleH(20));

        }];

        [_number_textfield mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerY.mas_equalTo(_price_label);
            make.right.mas_equalTo(_add_btn.mas_left).offset(autoScaleW(-2));
            make.width.mas_equalTo(autoScaleW(50));
            make.height.mas_equalTo(autoScaleH(20));

        }];

    [_subtract_btn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(_price_label);
        make.right.mas_equalTo(_number_textfield.mas_left).offset(autoScaleW(-2));
        make.width.mas_equalTo(autoScaleW(20));
        make.height.mas_equalTo(autoScaleH(20));

    }];


}

-(void)clickButton:(UIButton *)button{



    switch (button.tag) {
        case 101:
        {

            [self.delegate btnClick:self andFlag:(int)button.tag];

        }

            break;
        case 102:
        {
            if (self.selectState == YES)
            {
                //调用代理
                [self.delegate btnClick:self andFlag:(int)button.tag];
            }
        }
            break;
        case 103:
        {
            if (self.selectState == YES)
            {
                //调用代理
                [self.delegate btnClick:self andFlag:(int)button.tag];
            }
        }
            break;

        default:
            break;
    }

}
-(void)reloadWithModel:(shoppingCardModel *)model{

     NSLog(@"model.count=====%ld",model.count);

    self.title_label.text = [NSString stringWithFormat:@"%@", model.iconTitle];

    self.price_label.text = [NSString stringWithFormat:@"%ld", (long)model.price];

    self.number_textfield.text = [NSString stringWithFormat:@"%ld",(long)model.count];

    if (model.selectState){
        self.selectState = YES;
        [self.icon_btn setImage:[UIImage imageNamed:@"order_selected"] forState:UIControlStateNormal];
    }else{

        self.selectState = NO;
        [self.icon_btn setImage:[UIImage imageNamed:@"shop_normal"] forState:UIControlStateNormal];
    }



}


@end
